﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Agenda.Teste
{
  public partial class Calendar : Form
  {
    public Calendar()
    {
      InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
      
      calendario1.setCulture = "pt-PT";
      calendario1.FimDeSemanaColor = System.Drawing.SystemColors.ActiveCaption;
      
      calendario1.PriDiaSemana = DayOfWeek.Monday;
      calendario1.FimDeSemanaMostrar = true;

      calendario1.Nivel2Array = _nivel2;
      calendario1.Nivel3Array = _nivel3;
      calendario1.iniciar();

    }

    public void getDate(string _data)
    {
      MessageBox.Show(_data);
    }

    private void calendario1_SelectionChanged()
    {
      MessageBox.Show(calendario1.DataSelecionada().ToShortDateString());
    }
    DateTime[] _nivel2 = new DateTime[0];
    DateTime[] _nivel3 = new DateTime[0];
    Random radon = new Random();
    private void generateNumber()
    {
      DateTime temp1 = System.DateTime.Today;
      DateTime temp = System.DateTime.Today;
      _nivel2 = new DateTime[0];
      _nivel3 = new DateTime[0];
      int ntemp =0;
      for (int i = 0; i < 60; i++)
      {
        //ntemp = Random.
        temp = temp1.AddDays(radon.Next(0, 80));
        if ((temp.Day % 2) != 0)
        {
          DateTime[] _tempar = new DateTime[_nivel2.Length];
          Array.Copy(_nivel2, _tempar, _nivel2.Length);
          _nivel2 = new DateTime[_tempar.Length + 1];
          Array.Copy(_tempar, _nivel2, _tempar.Length);
          _nivel2[_nivel2.Length - 1] = temp;
          
        }
        else
        {
          DateTime[] _tempar = new DateTime[_nivel3.Length];
          Array.Copy(_nivel3, _tempar, _nivel3.Length);
          _nivel3 = new DateTime[_tempar.Length + 1];
          Array.Copy(_tempar, _nivel3, _tempar.Length);
          _nivel3[_nivel3.Length - 1] = temp;
        }
      }
    }

    private void button1_Click(object sender, EventArgs e)
    {
      generateNumber();
      textBox1.Clear();
      textBox2.Clear();
      if(_nivel2.Length>0)
        Array.Sort(_nivel2);
      if (_nivel3.Length > 0)
        Array.Sort(_nivel3);
      foreach (DateTime dt in _nivel2)
        textBox1.Text = textBox1.Text + Environment.NewLine + dt.ToShortDateString();
      foreach (DateTime dt in _nivel3)
        textBox2.Text = textBox2.Text + Environment.NewLine + dt.ToShortDateString();
    }

    private void button2_Click(object sender, EventArgs e)
    {
      if (calendario1.NivelMostrar == true)
      {
        calendario1.NivelMostrar = false;
      }
      else
        calendario1.NivelMostrar = true;
      calendario1.Nivel2Array = _nivel2;
      calendario1.Nivel3Array = _nivel3;
      calendario1._aspectoGrid();
    }

   

   

    
  }
}
